package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.Book;

import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collection;

/**
 * Created by florian on 26/12/13.
 */
public class BibliotecaUI {
    private final PrintStream printer;
    private static final String BOOK_TABLE_FORMAT = "%-5s | %-16s | %-15s\n";
    public BibliotecaUI(PrintStream printer) {
        this.printer = printer;
    }

    public void showWelcomeMessage() {
        printer.println("Welcome to Biblioteca");
    }

    public void listBooks(Collection<Book> books) {
        printer.format(BOOK_TABLE_FORMAT,"ID","Author","Title");
        printer.println("---------------------------------------------------------");
        for (Book book: books) {
            printer.format(BOOK_TABLE_FORMAT, book.getId(), book.getAuthor(), book.getTitle());
        }
    }

    public void showMenu() {
        printer.println("Main Menu\n" +
                "---------------------------------------------------------\n" +
                "1\tList available books\t\n" +
                "2\tCheckout book\n" +
                "3\tReturn book\n" +
                "q\tQuit");
        printer.print("Please select an option: ");
    }

    public void showInvalidMenuOptionMessage() {
        printer.print("ERROR: You selected an invalid option! Please select another option: ");
    }


    public void showCheckoutMessage() {
        printer.print("Please enter a book ID you want to check out: ");
    }

    public void showUnsuccessfulCheckoutMessage() {
        printer.println("That book is not available.");
    }

    public void showSuccessfulCheckoutMessage() {
        printer.println("Thank you! Enjoy the book!");
    }

    public void showReturnMessage() {
        printer.print("Please enter a book ID you want to return: ");
    }

    public void showUnsuccessfulReturnMessage() {
        printer.println("That is not a valid book to return.");
    }

    public void showSuccessfulReturnMessage() {
        printer.println("Thank you for returning the book!");
    }
}
